// https://vuex.vuejs.org/zh-cn/intro.html
// make sure to call Vue.use(Vuex) if using a module system
import Vue from 'vue'
import Vuex from 'vuex'
import http from '@/http/api'
import { UserTagDef } from "@/data";

Vue.use(Vuex)

const store = new Vuex.Store({
    state: {
        openid: '',
        userTagList: [],
        userFacilityList: [],
        uploadTypeId: '',
        locationInfo: null
    },
    mutations: {
        SET_USER_TAG_LIST(state, newTags) {
            state.userTagList = UserTagDef
        },
        SET_FACILITY_LIST(state, newFacility) {
            state.userFacilityList = newFacility
        }
    },
    actions: {
        GetUserTagList({ commit, state }) {
            return new Promise(async (resolve, reject) => {
                const { retCode, data } = await http.getTagList({ wxOpenId: state.openid }, false)
                if (retCode === 0) {
                    commit('SET_USER_TAG_LIST', data)
                }
                resolve()
            })
        },
        GetFacilityList({ commit, state }) {
            return new Promise(async (resolve, reject) => {
                const { retCode, data } = await http.getCategoryList({ action: 'wxUserGetAccessibilityFacilityCategoryList', wxOpenId: state.openid }, false)
                if (retCode === 0) {
                    commit('SET_FACILITY_LIST', data)
                }
                resolve()
            })
        },
    }
})



Vue.prototype.$store = store
export default store